package com.car.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;

import com.bbs.crawl.BBSCrawlOfBitAuto;
import com.bbs.dao.BBSDaoOfBitAuto;
import com.car.util.Util;

public class BitAutoError {
	private List<String> pp = new ArrayList<>();
	private List<String> tz = new ArrayList<>();

	public List<String> getPp() {
		return pp;
	}

	public List<String> getTz() {
		return tz;
	}

	public void readFileByLines(String fileName) {
		File file = new File(fileName);
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				Matcher m = Util.getMatched(tempString, "(.*)(http://.*\\.html)");
				if (m != null) {
					if (Util.getMatched(tempString, "(.*)(http://.*\\.html)").lookingAt()) {
						Matcher pin = Util.getMatched(tempString,
								"(.*)(http://baa\\.bitauto\\.com/.*/index-all-all-1-0\\.html)");
						Matcher tie = Util.getMatched(tempString,
								"(.*)(http://baa\\.bitauto\\.com/.*/thread-.*\\.html)");
						if (pin != null) {
							String pinpai = pin.group(2);
							pp.add(pinpai);
						}
						if (tie != null) {
							String tiezi = tie.group(2);
							tz.add(tiezi);
						}
					}
				}
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
	}

	public static void main(String[] args) {
		BitAutoError bit = new BitAutoError();
		bit.readFileByLines("E:/HeYanWorkSpace/carvoice/src/bbsbitauto_new.txt");
		List<String> pin = bit.getPp();
		List<String> tz = bit.getTz();
		BBSDaoOfBitAuto bbsdao = new BBSDaoOfBitAuto();
		ExecutorService fixedThreadPool = Executors.newFixedThreadPool(35);

		for (String p : pin) {
			String urlSpell = p.split("/")[3];
			fixedThreadPool.execute(new BBSCrawlOfBitAuto(bbsdao, urlSpell));
		}
	}
}
